<template>
  <div>
    <MainContent title="开发配置">
      <el-form label-width="120px">
        <el-card v-if="Store.state.user.adminType == 0" shadow="hover">
          <template #header>
            <div class="card-header">
              <span>超管开发配置</span>
              <el-button link type="primary" @click="adminReset" v-has="['140301']">重置</el-button>
            </div>
          </template>
          <el-form-item label="appId：">
            <el-col :span="18">{{ adminConfigData.appId }}</el-col>
          </el-form-item>
          <el-form-item label="aesKey：">
            <el-col :span="18">{{ adminConfigData.aesKey }}</el-col>
          </el-form-item>

          <el-form-item label="appSecret：">
            <el-col :span="18">{{ adminConfigData.appSecret }}</el-col>
          </el-form-item>
        </el-card>

        <el-card shadow="hover">
          <template #header>
            <div class="card-header">
              <span>机构开发配置</span>
              <el-button link type="primary" @click="reset" v-has="['140302']">重置</el-button>
            </div>
          </template>
          <el-form-item label="appId：">
            <el-col :span="18">{{ configData.appId }}</el-col>
          </el-form-item>
          <el-form-item label="aesKey：">
            <el-col :span="18">{{ configData.aesKey }}</el-col>
          </el-form-item>

          <el-form-item label="appSecret：">
            <el-col :span="18">{{ configData.appSecret }}</el-col>
          </el-form-item>
        </el-card>
      </el-form>
    </MainContent>
  </div>
</template>
<script lang="ts">
export default {
  name: 'ConfigSetting'
}
</script>
<script lang="ts" setup>
import SysConfigAip from "@/api/sysConfigApi";
const Store = useStore();
const configData = ref({
  aesKey: "",
  appId: "",
  appSecret: "",
});

const adminConfigData = ref({
  aesKey: "",
  appId: "",
  appSecret: "",
});

const reset = () => {
  ElMessageBox.confirm("是否重置？", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  }).then(() => {
    resetConfig();
  });
};

const adminReset = () => {
  ElMessageBox.confirm("是否重置？", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  }).then(() => {
    adminResetConfig();
  });
};
// getSystemInsConfig
// getSystemMerchantConfig
// resetSystemInsConfig
// resetSystemMerchantConfig

// 机构的
const adminGetSystemMerchantConfig = async () => {
  let rs: any = await SysConfigAip.getSystemMerchantConfig();
  if (rs.code === 200) {
    adminConfigData.value = rs.payload;
  }
};

const adminResetConfig = async () => {
  let rs: any = await SysConfigAip.resetSystemMerchantConfig();
  if (rs.code === 200) {
    ElMessage.success("重置成功");
    adminGetSystemMerchantConfig();
  }
};
//  机构的

//  超管的
const getSystemMerchantConfig = async () => {
  let rs: any = await SysConfigAip.getSystemInsConfig();
  if (rs.code === 200) {
    configData.value = rs.payload;
  }
};
const resetConfig = async () => {
  let rs: any = await SysConfigAip.resetSystemInsConfig();
  if (rs.code === 200) {
    ElMessage.success("重置成功");
    getSystemMerchantConfig();
  }
};

const store = useStore();
// 监听机构
const insId = computed(() => {
  return store.state.insId.insId;
});
watch(
  () => insId,
  () => {
    getSystemMerchantConfig();
    adminGetSystemMerchantConfig();
  },
  {
    deep: true
  }
)

// 超管的
onMounted(() => {
  getSystemMerchantConfig();
  adminGetSystemMerchantConfig();
});
</script>
<style lang="scss" scoped>
.el-card {
  margin-bottom: 20px;
}
.card-header {
  .el-button {
    margin-left: 20px;
  }
}
</style>
